package com.game.dao.living;

import com.coment.po.AnchorInfo;
import org.springframework.data.mongodb.repository.MongoRepository;

import java.util.Optional;

public interface AnchorInfoDao extends MongoRepository<AnchorInfo, Integer> {
   Optional<AnchorInfo> searchByApiTypeAndRoomId(String apiType, String roomId);


   default AnchorInfo searchOrCreateByApiTypeAndRoomId(String apiType, String roomId) {
      return searchByApiTypeAndRoomId(apiType, roomId).orElseGet(() -> {
         AnchorInfo info = new AnchorInfo(apiType,roomId);
         return save(info);
      });
   }
}
